<template>
    <!-- 应退采购款列表 -->
     <div style="background-color: #f0f2f5; padding: 20px">

    </div>

    <br/>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="本次计划退款金额：">
            <el-input style="width: 150px;" v-model="formInline.KPrice"/>-<el-input  style="width: 150px;" v-model="formInline.SPrice"/>
        </el-form-item>

        <el-form-item label="供应商名称：">
            <el-input v-model="formInline.VName"  style="width: 120px;" placeholder="请选择或输入" @dblclick="dialogVisible1 = true"/>
        </el-form-item>

        <el-form-item label="添加日期：" >
            <el-date-picker
                v-model="formInline.KDate"
                type="date"
                placeholder="请选择开始日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
            />
            -
            <el-date-picker
                v-model="formInline.SDate"
                type="date"
                placeholder="请选择结束日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
            />
        </el-form-item>

        <el-form-item label="退货人员：">
            <el-input v-model="formInline.PReturnsPersonnel"  style="width: 200px;"/>
        </el-form-item>

        <el-form-item label="已退款金额：">
            <el-input style="width: 150px;" v-model="formInline.PRtotalAmount"/>-<el-input  style="width: 150px;" v-model="formInline.SPRtotalAmount"/>
        </el-form-item>

        <el-form-item label="退款进度状态：">
            <el-select
                v-model="formInline.PROutboundProgress"
                placeholder="请选择退款进度状态"
                style="width: 200px;"
                clearable
            >
                <el-option label="全部" value="5" />
                <el-option label="未退款" value="0" />
                <el-option label="已退款" value="1" />
                <el-option label="部分退款" value="2" />
            </el-select>
        </el-form-item>

        <el-form-item label="计划退款日期：" >
            <el-date-picker
                v-model="formInline.KPRReturnDate"
                type="date"
                style="width: 200px;"
                placeholder="请选择开始日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
            />
            -
            <el-date-picker
                v-model="formInline.SPRReturnDate"
                type="date"
                style="width: 200px;"
                placeholder="请选择结束日期"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
            />
        </el-form-item>

        <el-form-item label="退款计划编号：">
            <el-input v-model="formInline.PRDocumentNumber" style="width: 200px;"/>
        </el-form-item>

        <el-form-item label="退款计划主题：">
            <el-input v-model="formInline.PurchaseReturnsTopic"  style="width: 200px;"/>
        </el-form-item>
        
        <el-form-item>
            <el-button type="primary" @click="GetPurchaseRefunds">查询</el-button>
        </el-form-item>
    </el-form>

    <br/>
    <h2 style="text-align: center;">应退采购款列表</h2>
    <br/>
    <el-table :data="Tables" style="width: 100%" @selection-change="handleSelectionChange1">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" width="55" label="序号" align="center" />
        <el-table-column prop="purchaseReturnsCode" label="退款计划编号" align="center" />
        <el-table-column prop="purchaseReturnsTopic" label="退款计划主题" align="center" />
        <el-table-column prop="vName" label="供应商名称" align="center">
            <template v-slot="scope">
                <a @click="vender(scope.row.vendorId)">{{ scope.row.vName }}</a>
            </template>
        </el-table-column>
        <el-table-column prop="prReturnDate" label="计划退款日期" align="center" >
            <template v-slot="scope">
                {{ scope.row.prReturnDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="addTime" label="制单日期" align="center" >
            <template v-slot="scope">
                {{ scope.row.addTime.substring(0, 10) }}
            </template>
        </el-table-column>

        <el-table-column prop="pReturnsPersonnel" label="退货人员" align="center" />
        <el-table-column prop="pRtotalAmount" label="本次计划退款金额" align="center" />
        <el-table-column prop="refundAmoun" label="已退款金额" align="center" />
        <el-table-column prop="prOutboundProgress" label="退款进度状态" align="center" >
            <template v-slot="scope">
                <el-text  v-if="scope.row.prOutboundProgress === 0" type="primary">未退款</el-text>
                <el-text  v-if="scope.row.prOutboundProgress === 1" type="success">已退款</el-text>
                <el-text  v-if="scope.row.prOutboundProgress === 2" type="danger">部分退款</el-text>
            </template>
        </el-table-column>
        <el-table-column prop="pReturnsPersonnel" label="" width="280px" align="center" >
            <template v-slot="scope">
                <el-button size="small" v-if="scope.row.prOutboundProgress==0 || scope.row.prOutboundProgress==2" @click="Tui(scope.row.purchaseReturnsIds,scope.row.purchaseReturnsCode)">退款(直接退款)</el-button>
                <el-button size="small" v-if="scope.row.prOutboundProgress==0 || scope.row.prOutboundProgress==2" @click="Tuis(scope.row.purchaseReturnsIds,scope.row.purchaseReturnsCode)">退款(转供应商预付款)</el-button>
            </template>
        </el-table-column>
        
    </el-table>

    <!-- 分页 -->
    <table style="margin: auto;">
        <tr>
            <td>
                <el-pagination v-model:current-page="page.Pindex" v-model:page-size="page.Psize"
                    :page-sizes="[15, 20, 30, 40]" :background="true" layout="total,slot,sizes" :total="page.lcount">
                    <span> , 每页 {{ page.Psize }} 条，当前 {{ page.Pindex }} / {{ page.pcount }} 条</span>
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="page.Pindex" v-model:page-size="page.Psize"
                    :page-sizes="[15, 20, 30, 40]" :background="true" prev-text="上一页" next-text="下一页"
                    layout="slot, prev, pager, next" :total="page.lcount">
                    <el-button :disabled="page.Pindex == 1" @click="page.Pindex = 1">首页</el-button>
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="page.Pindex" v-model:page-size="page.Psize"
                    :page-sizes="[15, 20, 30, 40]" :background="true" prev-text="上一页" next-text="下一页"
                    layout="slot, jumper" :total="page.lcount">
                    <el-button :disabled="page.Pindex == page.pcount" @click="page.Pindex = page.pcount">尾页</el-button>
                </el-pagination>
            </td>
        </tr>
    </table>


    <!-- 供应商弹框 -->
    <el-dialog
        v-model="dialogVisible1"
        title="供应商管理"
        width="800"
    >
        <el-table :data="tableData" border style="width: 100%"   @selection-change="handleSelectionChange1" >
            <el-table-column type="selection" width="55" />
            <el-table-column  label="序号" width="100"  type="index"  />
            <el-table-column prop="vNumber" label="供应商编号" width="100" />
            <el-table-column prop="vName" label="供应商名称" width="100" />
            <el-table-column prop="vGrade" label="供应商等级" width="100" />
            <el-table-column prop="sName" label="所在省份"   width="100"/>
            <el-table-column prop="cName" label="所在市" width="100" />
            <el-table-column prop="vendorTypeName" label="供应商类别"  width="100" />
            <el-table-column prop="hName" label="所属行业" width="100" />
            <el-table-column prop="vContact" label="联系人"  width="100" />
            <el-table-column prop="vDepartment" label="部门" width="100" />
            <el-table-column prop="vDuty" label="职位"   width="100"/>
            <el-table-column prop="bPhone" label="办公电话"  width="100"/>
            <el-table-column prop="vPhone" label="手机号码"  width="100"/>
         </el-table>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="Close1()">取消</el-button>
                    <el-button type="primary" @click="submi1()">
                    确定
                    </el-button>
                </div>
            </template>
  </el-dialog>

<!-- 直接退款弹框 -->
    <el-dialog
    v-model="dialogVisibles"
    title="新增采购退款(直接退款)"
    width="700"
  >
    <el-form
        ref="ruleFormRef"
        style="max-width: 600px"
        :model="form"
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
    >
        <el-form-item label="供应商名称">
            <el-input v-model="form.vName" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="退货人员:">
            <el-input v-model="form.pReturnsPersonnel" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="计划退款金额:">
            <el-input v-model="form.pRtotalAmount" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="关联退货单：">
            <el-input v-model="form.purchaseReturnsTopic" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="计划退货日期：">
            <el-date-picker v-model="form.prReturnDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="单据编号：">
            <el-input v-model="form.purchaseReturnsCode" style="width: 200px;" />
        </el-form-item>


        <el-form-item label="本次退款金额：" prop="benPrice" @change="GetPrice()">
            <el-input v-model="form.benPrice" style="width: 200px;" />
        </el-form-item>
         <el-form-item label="剩余退款金额：" >
            <el-input v-model="form.sengPrice" disabled style="width: 200px;" />
        </el-form-item>
        <el-form-item label="本次退款日期：" prop="benDate">
            <el-date-picker v-model="form.benDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="下次退款日期：" prop="xiaDate">
            <el-date-picker v-model="form.xiaDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="退款支付方式：">
            <el-select v-model="form.payType" style="width: 200px;" placeholder="请选择退货类别">
                <el-option label="现金" value="现金" />
                <el-option label="转账" value="转账" />
                <el-option label="支票" value="支票" />
                <el-option label="微信" value="微信" />
            </el-select>
        </el-form-item>
        <el-form-item label="退款银行账号：">
            <el-select v-model="form.yingHang" style="width: 200px;" placeholder="请选择退货类别" >
                <el-option label="无" value="无" />
                <el-option label="中国建设银行杭州市上城区支行" value="中国建设银行杭州市上城区支行" />
                <el-option label="中信银行河西路支行" value="中信银行河西路支行" />
                <el-option label="中国民生银行股份有限公司成都新都支行" value="中国民生银行股份有限公司成都新都支行" />
                <el-option label="上海浦发银行股份有限公司上海支行" value="上海浦发银行股份有限公司上海支行" />
                <el-option label="中国农业银行成都市金牛区支行" value="中国农业银行成都市金牛区支行" />
                <el-option label="中国农业银行双云路支行" value="中国农业银行双云路支行" />
                <el-option label="中国农业银行后海路支行" value="中国农业银行后海路支行" />
                <el-option label="中国农业银行琉璃街支行" value="中国农业银行琉璃街支行" />
                <el-option label="中国工商银行林京路支行" value="中国工商银行林京路支行" />
                <el-option label="建设银行大冶街支行" value="建设银行大冶街支行" />
                 <el-option label="中国农业银行小南街支行" value="中国农业银行小南街支行" />
            </el-select>
        </el-form-item>
         <el-form-item label="备注：">
             <el-input
                v-model="form.remark"
                style="width: 240px"
                :rows="2"
                type="textarea"
            />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" style="margin-left: 500px;" @click="submitForm(ruleFormRef)">
                保存
            </el-button>
            <!-- <el-button @click="resetForm(ruleFormRef)">Reset</el-button> -->
            </el-form-item>


    </el-form>
    
  </el-dialog>

  <!-- 直接退款(供应商预付款)弹框 -->
    <el-dialog
    v-model="dialogVisibles1"
    title="新增采购退款(转供应商预付款)"
    width="700"
  >
    <el-form
        ref="ruleFormRef"
        style="max-width: 600px"
        :model="forms"
        :rules="ruless"
        label-width="auto"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
    >
        <el-form-item label="供应商名称">
            <el-input v-model="forms.vName" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="退货人员:">
            <el-input v-model="forms.pReturnsPersonnel" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="计划退款金额:">
            <el-input v-model="forms.pRtotalAmount" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="关联退货单：">
            <el-input v-model="forms.purchaseReturnsTopic" style="width: 200px;" />
        </el-form-item>
        <el-form-item label="计划退货日期：">
            <el-date-picker v-model="forms.prReturnDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="单据编号：">
            <el-input v-model="forms.purchaseReturnsCode" style="width: 200px;" />
        </el-form-item>


        <el-form-item label="本次退款金额：" prop="benPrice" @change="GetPrices()">
            <el-input v-model="forms.benPrice" style="width: 200px;" />
        </el-form-item>
         <el-form-item label="剩余退款金额：" >
            <el-input v-model="forms.sengPrice" disabled style="width: 200px;" />
        </el-form-item>
        <el-form-item label="本次退款日期：" prop="benDate">
            <el-date-picker v-model="forms.benDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="下次退款日期：" prop="xiaDate">
            <el-date-picker v-model="forms.xiaDate"  type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                style="width: 200px;"  />
        </el-form-item>
        <el-form-item label="退款支付方式：">
            <el-select v-model="forms.payType" style="width: 200px;" placeholder="请选择退货类别">
                <el-option label="现金" value="现金" />
                <el-option label="转账" value="转账" />
                <el-option label="支票" value="支票" />
                <el-option label="微信" value="微信" />
            </el-select>
        </el-form-item>
        <el-form-item label="退款银行账号：">
            <el-select v-model="forms.yingHang" style="width: 200px;" placeholder="请选择退货类别" >
                <el-option label="无" value="无" />
                <el-option label="中国建设银行杭州市上城区支行" value="中国建设银行杭州市上城区支行" />
                <el-option label="中信银行河西路支行" value="中信银行河西路支行" />
                <el-option label="中国民生银行股份有限公司成都新都支行" value="中国民生银行股份有限公司成都新都支行" />
                <el-option label="上海浦发银行股份有限公司上海支行" value="上海浦发银行股份有限公司上海支行" />
                <el-option label="中国农业银行成都市金牛区支行" value="中国农业银行成都市金牛区支行" />
                <el-option label="中国农业银行双云路支行" value="中国农业银行双云路支行" />
                <el-option label="中国农业银行后海路支行" value="中国农业银行后海路支行" />
                <el-option label="中国农业银行琉璃街支行" value="中国农业银行琉璃街支行" />
                <el-option label="中国工商银行林京路支行" value="中国工商银行林京路支行" />
                <el-option label="建设银行大冶街支行" value="建设银行大冶街支行" />
                 <el-option label="中国农业银行小南街支行" value="中国农业银行小南街支行" />
            </el-select>
        </el-form-item>
         <el-form-item label="备注：">
             <el-input
                v-model="forms.remark"
                style="width: 240px"
                :rows="2"
                type="textarea"
            />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" style="margin-left: 500px;" @click="submitForm1(ruleFormRef)">
                保存
            </el-button>
            <!-- <el-button @click="resetForm(ruleFormRef)">Reset</el-button> -->
            </el-form-item>


    </el-form>
    
  </el-dialog>




</template>
    
<script setup lang='ts'>
import axios from 'axios';
import { ref, reactive, onMounted,watch} from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRoute,useRouter } from 'vue-router';
const route = useRoute()
const router = useRouter();
import http from '../../../http.js'

onMounted(() => {
    table();//显示供应商
    GetPurchaseRefunds();//显示采购退货单

})
//查询字段
const formInline = reactive({
    KPrice: '',
    SPrice: '',
    VName: '',
    KDate: '',
    SDate: '',
    PReturnsPersonnel: '',
    PRtotalAmount: '',
    SPRtotalAmount: '',
    PROutboundProgress: '',
    KPRReturnDate: '',
    SPRReturnDate: '',
    PRDocumentNumber: '',
    PurchaseReturnsTopic:''
})
//分页
const page = reactive({
    lcount: 0,//总数据
    pcount: 0,//尾页
    Pindex: 1,//当前页
    Psize:5
})

//显示采购退款
const Tables=ref([])
const GetPurchaseRefunds = () => {
    axios.get(http.zblnb+'/cg/api/PurchaseRefund/GetProcurementReturnList', {
        params: {

            Pindex: page.Pindex,
            Psize: page.Psize,
            KPrice: formInline.KPrice,
            SPrice: formInline.SPrice,
            VName: formInline.VName,
            KDate: formInline.KDate,
            SDate: formInline.SDate,
            PReturnsPersonnel: formInline.PReturnsPersonnel,
            PRtotalAmount: formInline.PRtotalAmount,
            SPRtotalAmount: formInline.SPRtotalAmount,
            PROutboundProgress: formInline.PROutboundProgress,
            KPRReturnDate: formInline.KPRReturnDate,
            SPRReturnDate: formInline.SPRReturnDate,
            PRDocumentNumber: formInline.PRDocumentNumber,
            PurchaseReturnsTopic:formInline.PurchaseReturnsTopic
        }
    })
    .then(res => {
        console.log(res.data)    
        Tables.value = res.data.data.list;
        page.lcount = res.data.data.lcount;
        page.pcount = res.data.data.pcount;
    })
    .catch(err => {
        console.log(err);    
    })
}

//跳转供应商名称
const vender = (vendorId: Number) => {
    router.push('/ListReturnsVendor?vendorId=' + vendorId);
}


//#region 供应商管理
const dialogVisible1=ref(false)
//供应商显示
var tableData=ref([]);
const table=()=>{
    axios.get(http.zblnb+'/cg/api/Vendor/ProductTypeSelectShow',{
    params:{
        FId:'',
        Node:'',
        Name:'',
        Sid:'',
        Cid:'',
        Hid:'',
        BPhone:'',
        SPhone:'',
        ZProper:'',
        PageIndex:1,
        PageSize:100
    }
    }).then(res=>{
        // console.log(res.data.data)
        if(res.data.code==200){
            tableData.value=res.data.data.list
    }
    })
}

//供应商弹框里的多选框
const vName=ref('')
const handleSelectionChange1 = (val:any) => {
    // check1.value = val
    vName.value = val;
    
}
//取消
const Close1 = () => {
    dialogVisible1.value= false
    formInline.VName = '';
}
//确定
const submi1 = () => {
    dialogVisible1.value = false
    formInline.VName = vName.value[0].vName;
}





//#endregion

//退款

//#region  直接退款
//直接退款

const dialogVisibles=ref(false)
const Tui = (purchaseReturnsIds: any, id: any) => {
    localStorage.setItem('purchaseReturnsIds',purchaseReturnsIds)
    dialogVisibles.value = true;
    // location.reload();//刷新
    axios.get(http.zblnb + '/cg/api/ProcurementReturn/FanProcurementReturn?PurchaseReturnsCode=' + id)
        .then(res => {
            console.log(res.data.data)
            let d = res.data.data;
            form.vName = d.vName;
            // form.pPurchasingStaff = d.pPurchasingStaff;
            form.purchaseReturnsCode = d.purchaseReturnsCode;
            form.purchaseReturnsTopic = d.purchaseReturnsTopic;
            form.pReturnsPersonnel = d.pReturnsPersonnel;
            // form.prCountpartPeople = d.prCountpartPeople;
            // form.prPeople = d.prPeople; check1.value
            // form.prReturnManner = d.prReturnManner;
            // form.prReturnAddress = d.prReturnAddress;
            form.prReturnDate = d.prReturnDate;
            // form.prReturnType = d.prReturnType;
            // form.prTotalQuantity = d.prTotalQuantity;
            form.pRtotalAmount = d.pRtotalAmount;
            // form.prDocumentNumber = d.prDocumentNumber;
            // form.rpNum = d.rpNum;
            form.rpPrice = d.rpPrice;
            // check1.value = d.productLists;
            // console.log(check1.value)

        })
}
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
const formSize = ref<ComponentSize>('default')
const ruleFormRef = ref<FormInstance>()
const locationOptions = ['Home', 'Company', 'School']

//退款(直接退款)添加
const form = reactive({
    "directRefundId": '11',
    "purchaseReturnsIds":localStorage.getItem('purchaseReturnsIds'),
    "vName": "",
    "pReturnsPersonnel": "",
    "pRtotalAmount": "",
    "purchaseReturnsTopic": "",
    "prReturnDate": "",
    "purchaseReturnsCode": "",
    "benPrice": "",
    "sengPrice": "",
    "benDate": "",
    "xiaDate": "",
    "payType": "",
    "yingHang": "",
    "remark": '',
    "rpPrice": "",
    "idddddd":1,
})

//根据输入的价钱来求出剩余金额 改变事件
const GetPrice = () => {
    // console.log(form.pRtotalAmount)
    // console.log(form.benPrice)
    form.sengPrice=Number(form.pRtotalAmount)-Number(form.benPrice)
}

//验证
const rules = reactive<FormRules>({
    benPrice: [
    { required: true, message: '本次退款金额不能为空', trigger: 'blur' },
    ],
   benDate: [
    { required: true, message: '本次退款日期不能为空', trigger: 'blur' },
    ],
   xiaDate: [
    { required: true, message: '下次退款日期不能为空', trigger: 'blur' },
   ],
})

//保存按钮
const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
      if (valid) {
            if (form.benPrice > form.pRtotalAmount) {
                ElMessage.warning('本次退款金额不能大于本次计划金额');
                return;
          }
            //下次退款日期不能低于本次退款日期
            if (form.xiaDate < form.benDate) {
                ElMessage.warning('下次退款日期不能低于本次退款日期');
                return;
            }
        axios.post(http.zblnb+'/cg/api/PurchaseRefund/AddDirectRefund',form)
        .then(res => {
            if (res.data.data > 0) {
                ElMessage.success('保存成功')
                dialogVisibles.value=false
                GetPurchaseRefunds();
            }    
            else {
                ElMessage.error('保存失败')
                return
            }
        })
    } else {
      console.log('error submit!', fields)
    }
  })
}



//#endregion


//#region  转供应商预付款
//供应商预付款

const dialogVisibles1=ref(false)
const Tuis = (purchaseReturnsIds: any, id: any) => {
    // location.reload();//刷新
    localStorage.setItem('purchaseReturnsIds',purchaseReturnsIds)
    dialogVisibles1.value = true;
    axios.get(http.zblnb + '/cg/api/ProcurementReturn/FanProcurementReturn?PurchaseReturnsCode=' + id)
        .then(res => {
            console.log(res.data.data)
            let d = res.data.data;
            forms.vName = d.vName;
            // form.pPurchasingStaff = d.pPurchasingStaff;
            forms.purchaseReturnsCode = d.purchaseReturnsCode;
            forms.purchaseReturnsTopic = d.purchaseReturnsTopic;
            forms.pReturnsPersonnel = d.pReturnsPersonnel;
            // form.prCountpartPeople = d.prCountpartPeople;
            // form.prPeople = d.prPeople; check1.value
            // form.prReturnManner = d.prReturnManner;
            // form.prReturnAddress = d.prReturnAddress;
            forms.prReturnDate = d.prReturnDate;
            // form.prReturnType = d.prReturnType;
            // form.prTotalQuantity = d.prTotalQuantity;
            forms.pRtotalAmount = d.pRtotalAmount;
            // form.prDocumentNumber = d.prDocumentNumber;
            // form.rpNum = d.rpNum;
            forms.rpPrice = d.rpPrice;
            // check1.value = d.productLists;
            // console.log(check1.value)

        })
}

//退款(直接退款)添加
const forms= reactive({
    "directRefundId": '11',
    "purchaseReturnsIds":localStorage.getItem('purchaseReturnsIds'),
    "vName": "",
    "pReturnsPersonnel": "",
    "pRtotalAmount": "",
    "purchaseReturnsTopic": "",
    "prReturnDate": "",
    "purchaseReturnsCode": "",
    "benPrice": "",
    "sengPrice": "",
    "benDate": "",
    "xiaDate": "",
    "payType": "",
    "yingHang": "",
    "remark": '',
    "rpPrice": "",
    "idddddd":2,
})

//根据输入的价钱来求出剩余金额 改变事件
const GetPrices = () => {
    // console.log(form.pRtotalAmount)
    // console.log(form.benPrice)
    forms.sengPrice=Number(forms.pRtotalAmount)-Number(forms.benPrice)
}

//验证
const ruless = reactive<FormRules>({
    benPrice: [
    { required: true, message: '本次退款金额不能为空', trigger: 'blur' },
    ],
   benDate: [
    { required: true, message: '本次退款日期不能为空', trigger: 'blur' },
    ],
   xiaDate: [
    { required: true, message: '下次退款日期不能为空', trigger: 'blur' },
   ],
})

//保存按钮
const submitForm1 = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
      if (valid) {
            if (forms.benPrice > forms.pRtotalAmount) {
                ElMessage.warning('本次退款金额不能大于本次计划金额');
                return;
            }
//下次退款日期不能低于本次退款日期
            if (forms.xiaDate < forms.benDate) {
                ElMessage.warning('下次退款日期不能低于本次退款日期');
                return;
            }
        axios.post(http.zblnb+'/cg/api/PurchaseRefund/AddDirectRefund',forms)
        .then(res => {
            if (res.data.data > 0) {
                ElMessage.success('保存成功')
                dialogVisibles1.value = false
                setTimeout(() => {
                    GetPurchaseRefunds();
                    location.reload();
                }, 1000);
            }    
            else {
                ElMessage.error('保存失败')
                return
            }
        })
    } else {
      console.log('error submit!', fields)
    }
  })
}



//#endregion


    
</script>
    
<style>
    
</style>